package cn.wolfcode.wolf2w.destination.controller;


import cn.wolfcode.wolf2w.common.core.domain.R;
import cn.wolfcode.wolf2w.destination.entity.TaDestination;
import cn.wolfcode.wolf2w.destination.entity.TaRegion;
import cn.wolfcode.wolf2w.destination.service.ITaDestinationService;
import cn.wolfcode.wolf2w.destination.service.ITaRegionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 目的地表 前端控制器
 * </p>
 *
 * @author hyz
 * @since 2024-07-23
 */
@RestController
@RequestMapping("/destinations")
public class TaDestinationController {

    @Autowired
    private ITaRegionService regionService;

    @Autowired
    private ITaDestinationService destinationService;

    @GetMapping("/regions")
    public R<List<TaRegion>> regions(int ishot){
        List<TaRegion> list = regionService.queryByState(ishot);
        return R.ok(list);
    }

    @GetMapping("/search")
    public R<List<TaDestination>> search(Long regionId){
        List<TaDestination> list = destinationService.queryByRegionId(regionId);
        return R.ok(list);
    }

    @GetMapping("/toasts")
    public Object toasts(Long destId){
        List<TaDestination> list = destinationService.queryToastsByDestId(destId);
        return R.ok(list);
    }

    @GetMapping("/list")
    public R<List<TaDestination>> list(){
//        List<TaDestination> list = destinationService.list();
        List<TaDestination> list = destinationService.listIncludeChildren();
        return R.ok(list);
    }

    //feign
    @GetMapping("/getById/{id}")
    public R<TaDestination> getById(@PathVariable("id") Long id){
        TaDestination dest = destinationService.getById(id);
        return R.ok(dest);
    }

    @GetMapping("/feign/list")
    public R<List<TaDestination>> feignList() {
        return R.ok(destinationService.list());
    }
}

